<template>
  <el-row>
    <el-col :lg="12">
      <el-card >
        <template #header>
          订单数据
        </template>
        <el-row justify="space-evenly">
          <el-statistic :title="formatSheet('今日利润',statisticsOrder.orderNumber1)"
                        :value="statisticsOrder.realProfit1" :formatter="formatRMB"/>
          <el-statistic :title="formatSheet('昨日利润',statisticsOrder.orderNumber2)"
                        :value="statisticsOrder.realProfit2" :formatter="formatRMB"/>
          <el-statistic :title="formatSheet('本周利润',statisticsOrder.orderNumber3)"
                        :value="statisticsOrder.realProfit3" :formatter="formatRMB"/>
          <el-statistic :title="formatSheet('本月利润',statisticsOrder.orderNumber4)"
                        :value="statisticsOrder.realProfit4" :formatter="formatRMB"/>
        </el-row>
      </el-card>
      <el-card>
        <template #header>
          待结算货款
        </template>
        <el-row justify="space-evenly">
          <el-statistic :title="formatSheet('进货',statisticsWithInSheet.sheetTotal)"
                        :value="statisticsWithInSheet.remainingAmount" :formatter="formatRMB"/>
          <el-statistic :title="formatSheet('退货',statisticsWithBackSheet.sheetTotal)"
                        :value="statisticsWithBackSheet.remainingAmount" :formatter="formatRMB"/>
        </el-row>
      </el-card>
    </el-col>
    <el-col :lg="12">

    </el-col>
  </el-row>
</template>

<script>

import supplierApi from "@/api/supplier.js";
import orderApi from "@/api/order.js";
import base from "@/utils/base.js";

export default {
  name: "index",
  mixins: [base],
  data() {
    return {
      statisticsWithInSheet: {},
      statisticsWithBackSheet: {},
      statisticsOrder: {},
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    loadData() {
      supplierApi.statisticsWithInSheet({status: 2}).then(res => {
        this.statisticsWithInSheet = res.data
      })
      supplierApi.statisticsWithBackSheet({status: 2}).then(res => {
        this.statisticsWithBackSheet = res.data
      })
      orderApi.statisticsBy12730({}).then(res => {
        this.statisticsOrder = res.data
      })
    },
    formatSheet(text, value) {
      if (value > 0) {
        return `${text} (${value}单)`
      }
      return text
    }
  }
}
</script>

<style lang="scss" scoped>
.el-card {
  margin-bottom: 16px;
}
</style>